package operation;

import Beans.Student;
import User.User;
import Utils.MenuInputUtil;
import Utils.SQLSentencePoll;
import dao.DataOperation;


/**
 * 删除学生账户的功能对象
 * -- 根据指定id查询待删除学生，并在删除前进行确认。
 */
public class DeleteStudentInfo implements IOperation{
    @Override
    public boolean operate(User user) {

        System.out.println("删除学生信息~");
        //查询指定id学生
        System.out.println("请输入您要删除的学生id（13位整数）：");
        String id = MenuInputUtil.readString(13);
        Student student = DataOperation.queryOne(Student.class, SQLSentencePoll.SpecifiedAccountInfoDisplay, id);
        if(student != null){
            System.out.println("该id下的学生信息：");
            System.out.println(student);
            System.out.println("确定是否删除？Y/N");
            char isDelete = MenuInputUtil.readConfirmSelection();
            if('Y' == isDelete || 'y' == isDelete){
                //删除学生
                DataOperation.update(SQLSentencePoll.SpecifiedAccountDeletion, id);
                System.out.println("已删除！");
            }
        }else{
            System.out.println("未查询到该学生！无法删除");
        }

        return true;
    }
}
